<script setup>
import { ref, h } from "vue";
import tvm from "../components/tvm.vue";
import largeFileUpload from "../components/largeFileUpload/index.vue";
import { dialog } from "../components/renderComp/render";
import "../components/concurrencyRequest/index.js";
import Worker from "../components/versionUpdateReminder/worker?worker";
import { gjhs } from "./gjhs";
defineProps({});
const bims = ref([]);
let old = Array.prototype;
let arr = Object.create(old);
arr["push"] = function (...arg) {
  console.log(arg);
  return old["push"].apply(this, arg);
};
let a = [];
a.__proto__ = arr;

a.push(1, 2, 3);

console.log(a);

//shash
window.addEventListener("hashchange", (val) => {});
setTimeout(() => {
  // window.location.hash = "123";
}, 5000);

//history
window.addEventListener("popstate", (val) => {});
const handleClick = () => {
  window.history.pushState({}, "", 123);
};

function t() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve();
    }, 5000);
  });
}

async function p() {
  await t();
  console.log("123");
}
p();
console.log("456");

function delay(delay) {
  let start = Date.now();
  while (start + delay > Date.now()) {}
}

Promise.resolve()
  .then(() => {
    console.log(1);
  })
  .then(() => {
    console.log(2);
  });

const kw = ref("123");

class L {
  #emap = new Map();
  constructor() {}
  on(name, fn) {
    if (!this.#emap.has(name)) {
      this.#emap.set(name, [fn]);
    } else {
      this.#emap.get(name).push(fn);
    }
  }
  emit(name, ...args) {
    const fns = this.#emap.get(name);
    if (fns) {
      fns.forEach((fn) => {
        if (fn && typeof fn === "function") {
          fn(args);
        }
      });
    }
  }
  off(name) {
    this.#emap.delete(name);
  }
}
let l = new L();
l.on("test", (data) => {
  console.log(this);
});

setTimeout(() => {
  l.emit("test", 123, 456, 789);
}, 3000);

dialog({
  title: "123123",
  slot: {
    default: h("div", 666),
  },
  closebtn: true,
});

const worker = new Worker();
// 向子线程发送消息，并传入文件对象和切片大小，开始计算分割切片
worker.postMessage("start");
worker.onmessage = (e) => {
  const { version } = e.data;
  if (+localStorage.getItem("version") !== version) {
    localStorage.setItem("version", version);
    alert("有新版本了,请刷新页面");
  }
};

const gjhsComp = gjhs();

const tindex = ref('测试')
</script>

<template>
  <div @click="handleClick">hello world</div>
  <tvm v-model="kw" />
  <p>{{ kw }}</p>
  <largeFileUpload />
  <gjhsComp />
  <tabs v-model="tindex">
    <tab-panel title="测试">aa</tab-panel>
    <tab-panel title="123">bb</tab-panel>
  </tabs>
</template>

<style scoped></style>
